from fastapi import Form, Request, APIRouter, Depends
from app.config import SessionLocal, engine
from app.sql import models
from . import crud
from app.sql.schema import DetectorCreate
from sqlalchemy.orm import Session

stalker_router = APIRouter(prefix="/api/stalker")

def get_db():
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()

@stalker_router.post("/add")
def add_data(model: DetectorCreate,db: Session = Depends(get_db)):
    return crud.add_detector(model, db)

@stalker_router.get("/pretty_anomalies")
def get_data(db: Session = Depends(get_db)):
    return crud.get_anomalies(db)